// *** LICENSE HEADER ***
// Filename: ./engine.h
// This file is part of Nodewarz 0.1
// Nodewarz is a 3d OpenGL strategy game
// Copyright (C) 2007 CZestmyr
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// *** END LICENSE HEADER ***
#ifndef NODEWARS_ENGINE_H
#define NODEWARS_ENGINE_H

#include <SDL.h>
#include <SDL_net.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "gamestate.h"
#include "logger.h"
#include "eventmanager.h"
#include "mainmenu.h"
#include "fonts.h"
#include "game.h"
#include "particlesystem.h"
#include "roster.h"
#include "button.h"
#include "canvas.h"
#include "buttonids.h"
#include "connector.h"
#include "definitions.h"
#include "guielement.h"
#include "numberfield.h"
#include "gui.h"
#include "messageviewer.h"
#include "playerlist.h"
#include "player.h"
#include "node.h"
#include "nodegraph.h"
#include "resourcelist.h"
#include "resource.h"
#include "camera.h"
#include "helperfunctions.h"

class mainMenu;
class fonts;
class game;
class roster;
class connector;
class messageViewer;
class node;

//The main program class that handles timing, game states, SDL and openGL init stuff, etc...
class engine {
    public:
        engine(const char* logFile);
        ~engine();

        //Initialize the game engine
        bool Init();
        //Create an SDL window
        bool SDLCreateWindow();
        //Deinitialize the game engine
        void Deinit();
        //Tell whether the engine is still running
        bool Run();
        //Update the engine (and the whole game)
        void Update();
        //Draw everything
        void Draw();
        //Switch between gamestates
        void SwitchState(gamestate state);
        //Get the current game state
        gamestate GetState();

        //Get the FPS number
        int GetFPS();
        //Close the application
        void Quit();

        //Get various game subsystems
        logger* GetLogger();
        fonts* GetFonts();
        game* GetGame();
        connector* GetConnector();
        roster* GetRoster();
        messageViewer* GetMessageViewer();

        //The function that runs when a client disconnects during the game
        void ClientDisconnected(int client);
        //The function that is run when the server quits during the game
        void ServerDisconnected();

        //Callback function that handles gui element events
        static void GuiCallback(engine* me, int elementId);
        //Callback function that is called when a network event arrives
        static void NetEventCallback(engine* me, const char* messageBuffer);
    private:
        //Current game state
        gamestate currentState;
        //The gamestate that we will switch into
        gamestate toSwitch;
        //Should we switch the gamestate?
        bool switchGameState;
        //Are we running?
        bool run;

        //Last frame's timestamp
        Uint32 timestamp;
        //Current FPS
        int fps;

        //Subsystems
        logger* theLogger;
        eventManager* theEventManager;
        mainMenu* theMainMenu;
        fonts* theFonts;
        game* theGame;
        roster* theRoster;
        connector* theConnector;
        messageViewer* theMessageViewer;
};

#endif
